﻿Imports System.Data.OleDb
Public Class NguyenLieuDAO
    Public Function Insert(ByVal tmp As NguyenLieuDTO) As Integer
        Dim cn As OleDbConnection = DataProvider.ConnectionData()
        Dim str As String = "insert into NguyenLieu (TenNguyenLieu,NguonGoc,NgayNhap,Gia) values (@TenNguyenLieu,@NguonGoc,@NgayNhap,@Gia)"
        Dim cmd As OleDbCommand = New OleDbCommand(str, cn)
        Dim para1, para2, para4, para5 As OleDbParameter
        para1 = New OleDbParameter("@TenNguyenLieu", tmp.TenNguyenLieu)
        cmd.Parameters.Add(para1)
        para2 = New OleDbParameter("@NguonGoc", tmp.NguonGoc)
        cmd.Parameters.Add(para2)
        para4 = New OleDbParameter("@NgayNhap", tmp.NgayNhap)
        cmd.Parameters.Add(para4)
        para5 = New OleDbParameter("@Gia", tmp.Gia)
        cmd.Parameters.Add(para5)
        Dim result As Integer = cmd.ExecuteNonQuery()
        cn.Close()
        Return result
    End Function

    Public Function Update(ByVal tmp As NguyenLieuDTO) As Integer
        Dim cn As OleDbConnection = DataProvider.ConnectionData()
        Dim str As String = "Update NguyenLieu set TenNguyenLieu=@TenNguyenLieu,NguonGoc=@NguonGoc,NgayNhap=@NgayNhap,Gia=@Gia where MaNguyenLieu=@MaNguyenLieu "
        Dim cmd As OleDbCommand = New OleDbCommand(str, cn)
        Dim para0, para1, para2, para4, para5 As OleDbParameter
        para0 = New OleDbParameter("MaNguyenLieu", tmp.MaNguyenLieu)
        cmd.Parameters.Add(para0)
        para1 = New OleDbParameter("@TenNguyenLieu", tmp.TenNguyenLieu)
        cmd.Parameters.Add(para1)
        para2 = New OleDbParameter("@NguonGoc", tmp.NguonGoc)
        cmd.Parameters.Add(para2)
        para4 = New OleDbParameter("@NgayNhap", tmp.NgayNhap)
        cmd.Parameters.Add(para4)
        para5 = New OleDbParameter("@Gia", tmp.Gia)
        cmd.Parameters.Add(para5)
        Dim result As Integer = cmd.ExecuteNonQuery()
        cn.Close()
        Return result
    End Function

    Public Function Delete(ByVal tmp As NguyenLieuDTO) As Integer
        Dim cn As OleDbConnection = DataProvider.ConnectionData()
        Dim str As String = "delete from NguyenLieu where MaNguyenLieu=@MaNguyenLieu"
        Dim cmd As OleDbCommand = New OleDbCommand(str, cn)
        Dim para1 As OleDbParameter
        para1 = New OleDbParameter("@MaNguyenLieu", tmp.MaNguyenLieu)
        cmd.Parameters.Add(para1)
        Dim result As Integer = cmd.ExecuteNonQuery()
        cn.Close()
        Return result
    End Function

    Public Function GetTable(ByVal t As String) As DataTable
        Dim dt As DataTable = New DataTable()
        Dim cn As OleDbConnection = DataProvider.ConnectionData()
        Dim str As String = t
        Dim da As OleDbDataAdapter = New OleDbDataAdapter(str, cn)
        da.Fill(dt)
        cn.Close()
        Return dt
    End Function

    Public Function GetValue(ByVal t As String) As String
        Dim cn As OleDbConnection = DataProvider.ConnectionData()
        Dim str As String = t
        Dim cmd As OleDbCommand = New OleDbCommand(str, cn)
        Dim kq As String = cmd.ExecuteScalar()
        Return kq
    End Function
End Class
